<?php
require_once("/var/www/html/new/conf/le.je");
include '../../common/func.inc.php';
use pft\Member\MemberAccount;
include '/var/www/html/new/d/class/MemberAccount.class.php';
use pft\Sms\SmsNotify;
use pft\notice;
$le=new go_sql();
$le->connect();
$soap = new SoapClient(null,array(
        "location" => "http://localhost/open/openService/pft_insideMX.php",
        "uri" => "www.16u.com?ac_16u=16ucom|pw_16u=c33367701511b4f6020ec61ded352059|auth_16u=true")
);
$stype = $_REQUEST['stype'];
$account = $_REQUEST['account'];
$money = $_REQUEST['money'];
$sms_tpl_file = "{$stype}.txt";
if(!isset($_SESSION['account']))
{
    exit ('{"status":"fail"}');
}
/*查询短信是否存在*/
if(file_exists($sms_tpl_file)) {
    $tpl = file_get_contents($sms_tpl_file);
    /*查询转账账户的号码、姓名*/
    $sql = "SELECT mobile,dname FROM pft_member WHERE account='{$_SESSION['account']}' limit 1 ";
    $GLOBALS['le']->query($sql);
    $row=$GLOBALS['le']->fetch_assoc();
    $r[] = $row;
    /*查询被转的用户的姓名*/
    $sql_tr = "SELECT dname FROM pft_member WHERE account='$account' limit 1 ";
    $GLOBALS['le']->query($sql_tr);
    $row_tr=$GLOBALS['le']->fetch_assoc();
    $r_tr[] = $row_tr;
//var_dump($row_tr);
//exit;
    if(empty($row_tr))
    {
        $return = array(
            'status'=>'empty'
        );
    }
    else
    {
        /*短信内容的替换*/
        $chinese=array("【","】");
        $english = array("[","]");
        $r_tr[0]['dname']=str_replace($chinese,$english, $r_tr[0]['dname']);
        $search = array('{tredid}','{tredname}','{money}');
        $replace = array($account,$r_tr[0]['dname'],$money);
        $content = str_replace($search,$replace, $tpl);
        /*转账用户的手机号码*/
        $mobile=$r[0]['mobile'];
        if( empty($_SESSION['timer']) || time()-$_SESSION['timer']>60  )
        {
            $r = MemberAccount::sendVcode($mobile, $content, $soap);
            if($r==100)
            {
                $return = array(
                    'status'=>'suc'
                );
            }
            else
                $return = array(
                    'status'=>'fail'
                );
        }
        else
        {
            $return = array(
                'status'=>'lesstime'
            );
        }
    }
}
else {
    $return = array(
        'status'=>'message'
    );
//    exit ('{"status":"fail","msg":"短信模板不存在！"}');
}
echo json_encode($return);
?>